home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 60.zip / BS1 part 60 / Cnet 2.60 d2.adf / programming / minrexx.h < prev    next >
C/C++ Source or Header  |  1993-02-10  |  17KB  |  317 lines

  1. /* The NexxStr structure is used to maintain the internal strings in REXX.
  2.  * It includes the buffer area for the string and associated attributes.
  3.  * This is actually a variable-length structure; it is allocated for a
  4.  * specific length string, and the length is never modified thereafter
  5.  * (since it's used for recycling).
  6.  */
  7.  
  8. struct NexxStr {
  9.    LONG     ns_Ivalue;                 /* integer value                 */
  10.    UWORD    ns_Length;                 /* length in bytes (excl null)   */
  11.    UBYTE    ns_Flags;                  /* attribute flags               */
  12.    UBYTE    ns_Hash;                   /* hash code                     */
  13.    BYTE     ns_Buff[8];                /* buffer area for strings       */
  14.    };                                  /* size: 16 bytes (minimum)      */
  15.  
  16. #define NXADDLEN 9                     /* offset plus null byte         */
  17. #define IVALUE(nsPtr) (nsPtr->ns_Ivalue)
  18.  
  19. /* String attribute flag bit definitions                                */
  20. #define NSB_KEEP     0                 /* permanent string?             */
  21. #define NSB_STRING   1                 /* string form valid?            */
  22. #define NSB_NOTNUM   2                 /* non-numeric?                  */
  23. #define NSB_NUMBER   3                 /* a valid number?               */
  24. #define NSB_BINARY   4                 /* integer value saved?          */
  25. #define NSB_FLOAT    5                 /* floating point format?        */
  26. #define NSB_EXT      6                 /* an external string?           */
  27. #define NSB_SOURCE   7                 /* part of the program source?   */
  28.  
  29. /* The flag form of the string attributes                               */
  30. #define NSF_KEEP     (1 << NSB_KEEP  )
  31. #define NSF_STRING   (1 << NSB_STRING)
  32. #define NSF_NOTNUM   (1 << NSB_NOTNUM)
  33. #define NSF_NUMBER   (1 << NSB_NUMBER)
  34. #define NSF_BINARY   (1 << NSB_BINARY)
  35. #define NSF_FLOAT    (1 << NSB_FLOAT )
  36. #define NSF_EXT      (1 << NSB_EXT   )
  37. #define NSF_SOURCE   (1 << NSB_SOURCE)
  38.  
  39. /* Combinations of flags                                                */
  40. #define NSF_INTNUM   (NSF_NUMBER | NSF_BINARY | NSF_STRING)
  41. #define NSF_DPNUM    (NSF_NUMBER | NSF_FLOAT)
  42. #define NSF_ALPHA    (NSF_NOTNUM | NSF_STRING)
  43. #define NSF_OWNED    (NSF_SOURCE | NSF_EXT    | NSF_KEEP)
  44. #define KEEPSTR      (NSF_STRING | NSF_SOURCE | NSF_NOTNUM)
  45. #define KEEPNUM      (NSF_STRING | NSF_SOURCE | NSF_NUMBER | NSF_BINARY)
  46.  
  47. /* The RexxArg structure is identical to the NexxStr structure, but
  48.  * is allocated from system memory rather than from internal storage.
  49.  * This structure is used for passing arguments to external programs.
  50.  * It is usually passed as an "argstring", a pointer to the string buffer.
  51.  */
  52.  
  53. struct RexxArg {
  54.    LONG     ra_Size;                   /* total allocated length        */
  55.    UWORD    ra_Length;                 /* length of string              */
  56.    UBYTE    ra_Flags;                  /* attribute flags               */
  57.    UBYTE    ra_Hash;                   /* hash code                     */
  58.    BYTE     ra_Buff[8];                /* buffer area                   */
  59.    };                                  /* size: 16 bytes (minimum)      */
  60.  
  61. /* The RexxMsg structure is used for all communications with REXX
  62.  * programs.  It is an EXEC message with a parameter block appended.
  63.  */
  64.  
  65. struct RexxMsg {
  66.    struct Message rm_Node;             /* EXEC message structure        */
  67.    APTR     rm_TaskBlock;              /* global structure (private)    */
  68.    APTR     rm_LibBase;                /* library base (private)        */
  69.    LONG     rm_Action;                 /* command (action) code         */
  70.    LONG     rm_Result1;                /* primary result (return code)  */
  71.    LONG     rm_Result2;                /* secondary result              */
  72.    STRPTR   rm_Args[16];               /* argument block (ARG0-ARG15)   */
  73.  
  74.    struct MsgPort *rm_PassPort;        /* forwarding port               */
  75.    STRPTR   rm_CommAddr;               /* host address (port name)      */
  76.    STRPTR   rm_FileExt;                /* file extension                */
  77.    LONG     rm_Stdin;                  /* input stream (filehandle)     */
  78.    LONG     rm_Stdout;                 /* output stream (filehandle)    */
  79.    LONG     rm_avail;                  /* future expansion              */
  80.    };                                  /* size: 128 bytes               */
  81.  
  82. /* Field definitions                                                    */
  83. #define ARG0(rmp) (rmp->rm_Args[0])    /* start of argblock             */
  84. #define ARG1(rmp) (rmp->rm_Args[1])    /* first argument                */
  85. #define ARG2(rmp) (rmp->rm_Args[2])    /* second argument               */
  86.  
  87. #define MAXRMARG  15                   /* maximum arguments             */
  88.  
  89. /* Command (action) codes for message packets                           */
  90. #define RXCOMM    0x01000000           /* a command-level invocation    */
  91. #define RXFUNC    0x02000000           /* a function call               */
  92. #define RXCLOSE   0x03000000           /* close the REXX server         */
  93. #define RXQUERY   0x04000000           /* query for information         */
  94. #define RXADDFH   0x07000000           /* add a function host           */
  95. #define RXADDLIB  0x08000000           /* add a function library        */
  96. #define RXREMLIB  0x09000000           /* remove a function library     */
  97. #define RXADDCON  0x0A000000           /* add/update a ClipList string  */
  98. #define RXREMCON  0x0B000000           /* remove a ClipList string      */
  99. #define RXTCOPN   0x0C000000           /* open the trace console        */
  100. #define RXTCCLS   0x0D000000           /* close the trace console       */
  101.  
  102. /* Command modifier flag bits                                           */
  103. #define RXFB_NOIO    16                /* suppress I/O inheritance?     */
  104. #define RXFB_RESULT  17                /* result string expected?       */
  105. #define RXFB_STRING  18                /* program is a "string file"?   */
  106. #define RXFB_TOKEN   19                /* tokenize the command line?    */
  107. #define RXFB_NONRET  20                /* a "no-return" message?        */
  108.  
  109. /* The flag form of the command modifiers                               */
  110. #define RXFF_NOIO    (1L << RXFB_NOIO  )
  111. #define RXFF_RESULT  (1L << RXFB_RESULT)
  112. #define RXFF_STRING  (1L << RXFB_STRING)
  113. #define RXFF_TOKEN   (1L << RXFB_TOKEN )
  114. #define RXFF_NONRET  (1L << RXFB_NONRET)
  115.  
  116. #define RXCODEMASK   0xFF000000
  117. #define RXARGMASK    0x0000000F
  118.  
  119. /* The RexxRsrc structure is used to manage global resources.  Each node 
  120.  * has a name string created as a RexxArg structure, and the total size
  121.  * of the node is saved in the "rr_Size" field.  The REXX systems library
  122.  * provides functions to allocate and release resource nodes.  If special
  123.  * deletion operations are required, an offset and base can be provided in
  124.  * "rr_Func" and "rr_Base", respectively.  This "autodelete" function will
  125.  * be called with the base in register A6 and the node in A0.
  126.  */
  127.  
  128. struct RexxRsrc {
  129.    struct Node rr_Node;
  130.    WORD     rr_Func;                   /* "auto-delete" offset          */
  131.    APTR     rr_Base;                   /* "auto-delete" base            */
  132.    LONG     rr_Size;                   /* total size of node            */
  133.    LONG     rr_Arg1;                   /* available ...                 */
  134.    LONG     rr_Arg2;                   /* available ...                 */
  135.    };                                  /* size: 32 bytes                */
  136.  
  137. /* Resource node types                                                  */
  138. #define RRT_ANY      0                 /* any node type ...             */
  139. #define RRT_LIB      1                 /* a function library            */
  140. #define RRT_PORT     2                 /* a public port                 */
  141. #define RRT_FILE     3                 /* a file IoBuff                 */
  142. #define RRT_HOST     4                 /* a function host               */
  143. #define RRT_CLIP     5                 /* a Clip List node              */
  144.  
  145. /* The RexxTask structure holds the fields used by REXX to communicate with
  146.  * external processes, including the client task.  It includes the global
  147.  * data structure (and the base environment).  The structure is passed to
  148.  * the newly-created task in its "wake-up" message.
  149.  */
  150.  
  151. #define GLOBALSZ  200                  /* total size of GlobalData      */
  152.  
  153. struct RexxTask {
  154.    BYTE     rt_Global[GLOBALSZ];       /* global data structure         */
  155.    struct MsgPort rt_MsgPort;          /* global message port           */
  156.    UBYTE    rt_Flags;                  /* task flag bits                */
  157.    BYTE     rt_SigBit;                 /* signal bit                    */
  158.  
  159.    APTR     rt_ClientID;               /* the client's task ID          */
  160.    APTR     rt_MsgPkt;                 /* the packet being processed    */
  161.    APTR     rt_TaskID;                 /* our task ID                   */
  162.    APTR     rt_RexxPort;               /* the REXX public port          */
  163.  
  164.    APTR     rt_ErrTrap;                /* Error trap address            */
  165.    APTR     rt_StackPtr;               /* stack pointer for traps       */
  166.  
  167.    struct List rt_Header1;             /* Environment list              */
  168.    struct List rt_Header2;             /* Memory freelist               */
  169.    struct List rt_Header3;             /* Memory allocation list        */
  170.    struct List rt_Header4;             /* Files list                    */
  171.    struct List rt_Header5;             /* Message Ports List            */
  172.    };
  173.  
  174. /* Definitions for RexxTask flag bits                                   */
  175. #define RTFB_TRACE   0                 /* external trace flag           */
  176. #define RTFB_HALT    1                 /* external halt flag            */
  177. #define RTFB_SUSP    2                 /* suspend task?                 */
  178. #define RTFB_TCUSE   3                 /* trace console in use?         */
  179. #define RTFB_WAIT    6                 /* waiting for reply?            */
  180. #define RTFB_CLOSE   7                 /* task completed?               */
  181.  
  182. /* Definitions for memory allocation constants                          */
  183. #define MEMQUANT  16L                  /* quantum of memory space       */
  184. #define MEMMASK   0xFFFFFFF0           /* mask for rounding the size    */
  185.  
  186. #define MEMQUICK  (1L << 0 )           /* EXEC flags: MEMF_PUBLIC       */
  187. #define MEMCLEAR  (1L << 16)           /* EXEC flags: MEMF_CLEAR        */
  188.  
  189. /* The SrcNode is a temporary structure used to hold values destined for
  190.  * a segment array.  It is also used to maintain the memory freelist.
  191.  */
  192.  
  193. struct SrcNode {
  194.    struct SrcNode *sn_Succ;            /* next node                     */
  195.    struct SrcNode *sn_Pred;            /* previous node                 */
  196.    APTR     sn_Ptr;                    /* pointer value                 */
  197.    LONG     sn_Size;                   /* size of object                */
  198.    };                                  /* size: 16 bytes                */
  199.  
  200. /* Some macro definitions                                               */
  201.  
  202. #define RXSNAME  "rexxsyslib.library"
  203. #define RXSID    "rexxsyslib 1.06 (07 MAR 88)\n"
  204. #define RXSDIR   "REXX"
  205. #define RXSTNAME "ARexx"
  206.  
  207. /* The REXX systems library structure.  This should be considered as    */
  208. /* semi-private and read-only, except for documented exceptions.        */
  209.  
  210. struct RxsLib {
  211.    struct Library rl_Node;             /* EXEC library node             */
  212.    UBYTE    rl_Flags;                  /* global flags                  */
  213.    UBYTE    rl_pad;
  214.    APTR     rl_SysBase;                /* EXEC library base             */
  215.    APTR     rl_DOSBase;                /* DOS library base              */
  216.    APTR     rl_IeeeDPBase;             /* IEEE DP math library base     */
  217.    LONG     rl_SegList;                /* library seglist               */
  218.    LONG     rl_NIL;                    /* global NIL: filehandle        */
  219.    LONG     rl_Chunk;                  /* allocation quantum            */
  220.    LONG     rl_MaxNest;                /* maximum expression nesting    */
  221.    struct NexxStr *rl_NULL;            /* static string: NULL           */
  222.    struct NexxStr *rl_FALSE;           /* static string: FALSE          */
  223.    struct NexxStr *rl_TRUE;            /* static string: TRUE           */
  224.    struct NexxStr *rl_REXX;            /* static string: REXX           */
  225.    struct NexxStr *rl_COMMAND;         /* static string: COMMAND        */
  226.    struct NexxStr *rl_STDIN;           /* static string: STDIN          */
  227.    struct NexxStr *rl_STDOUT;          /* static string: STDOUT         */
  228.    struct NexxStr *rl_STDERR;          /* static string: STDERR         */
  229.    STRPTR    rl_Version;               /* version/configuration string  */
  230.  
  231.    STRPTR    rl_TaskName;              /* name string for tasks         */
  232.    LONG      rl_TaskPri;               /* starting priority             */
  233.    LONG      rl_TaskSeg;               /* startup seglist               */
  234.    LONG      rl_StackSize;             /* stack size                    */
  235.    STRPTR    rl_RexxDir;               /* REXX directory                */
  236.    STRPTR    rl_CTABLE;                /* character attribute table     */
  237.    struct NexxStr *rl_Notice;          /* copyright notice              */
  238.  
  239.    struct MsgPort rl_RexxPort;         /* REXX public port              */
  240.    UWORD     rl_ReadLock;              /* lock count                    */
  241.    LONG      rl_TraceFH;               /* global trace console          */
  242.    struct List rl_TaskList;            /* REXX task list                */
  243.    WORD      rl_NumTask;               /* task count                    */
  244.    struct List rl_LibList;             /* Library List header           */
  245.    WORD      rl_NumLib;                /* library count                 */
  246.    struct List rl_ClipList;            /* ClipList header               */
  247.    WORD      rl_NumClip;               /* clip node count               */
  248.    struct List rl_MsgList;             /* pending messages              */
  249.    WORD      rl_NumMsg;                /* pending count                 */
  250.    struct List rl_PgmList;             /* cached programs               */
  251.    WORD      rl_NumPgm;                /* program count                 */
  252.  
  253.    UWORD     rl_TraceCnt;              /* usage count for trace console */
  254.    WORD      rl_avail;
  255.    };
  256.  
  257. /* Global flag bit definitions for RexxMaster                           */
  258. #define RLFB_TRACE RTFB_TRACE          /* interactive tracing?          */
  259. #define RLFB_HALT  RTFB_HALT           /* halt execution?               */
  260. #define RLFB_SUSP  RTFB_SUSP           /* suspend execution?            */
  261. #define RLFB_STOP  6                   /* deny further invocations      */
  262. #define RLFB_CLOSE 7                   /* close the master              */
  263.  
  264. #define RLFMASK    (1<<RLFB_TRACE) | (1<<RLFB_HALT) | (1<<RLFB_SUSP)
  265.  
  266. /* Initialization constants                                             */
  267. #define RXSVERS    34                  /* main version                  */
  268. #define RXSREV     7                   /* revision                      */
  269. #define RXSALLOC   0x800000            /* maximum allocation            */
  270. #define RXSCHUNK   1024                /* allocation quantum            */
  271. #define RXSNEST    32                  /* expression nesting limit      */
  272. #define RXSTPRI    0                   /* task priority                 */
  273. #define RXSSTACK   4096                /* stack size                    */
  274. #define RXSLISTH   5                   /* number of list headers        */
  275.  
  276. /* Character attribute flag bits used in REXX.                          */
  277. #define CTB_SPACE   0                  /* white space characters        */
  278. #define CTB_DIGIT   1                  /* decimal digits 0-9            */
  279. #define CTB_ALPHA   2                  /* alphabetic characters         */
  280. #define CTB_REXXSYM 3                  /* REXX symbol characters        */
  281. #define CTB_REXXOPR 4                  /* REXX operator characters      */
  282. #define CTB_REXXSPC 5                  /* REXX special symbols          */
  283. #define CTB_UPPER   6                  /* UPPERCASE alphabetic          */
  284. #define CTB_LOWER   7                  /* lowercase alphabetic          */
  285.                                                                       
  286. /* Attribute flags                                                      */
  287. #define CTF_SPACE   (1 << CTB_SPACE)
  288. #define CTF_DIGIT   (1 << CTB_DIGIT)
  289. #define CTF_ALPHA   (1 << CTB_ALPHA)
  290. #define CTF_REXXSYM (1 << CTB_REXXSYM)
  291. #define CTF_REXXOPR (1 << CTB_REXXOPR)
  292. #define CTF_REXXSPC (1 << CTB_REXXSPC)
  293. #define CTF_UPPER   (1 << CTB_UPPER)
  294. #define CTF_LOWER   (1 << CTB_LOWER)
  295.  
  296. /*
  297.  *   This is the list of functions we can access.  (Cheap forward
  298.  *   declarations, too.)
  299.  */
  300.  
  301. /*
  302.  *   Maximum messages that can be pending, and the return codes
  303.  *   for two bad situations.
  304.  */
  305. #define MAXRXOUTSTANDING (300)
  306. #define RXERRORIMGONE (100)
  307. #define RXERRORNOCMD (30)
  308. /*
  309.  *   This is the association list you build up (statically or
  310.  *   dynamically) that should be terminated with an entry with
  311.  *   NULL for the name . . .
  312.  */
  313. struct rexxCommandList {
  314.    char *name ;
  315.    char *(*userdata)() ;
  316. };
  317.